package com.inspur.security.cbb3.kms.keymanager.secrets.po;

import java.io.Serializable;
import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.hibernate.annotations.GenericGenerator;
import lombok.Data;

/**
 * @Description	密钥表
 * @author  lijunchang
 */

@Entity
@Table ( name ="tb_secrets" )
@Data
public class SecretsBean implements Serializable {

	private static final long serialVersionUID =  2177200487529058389L;

	/**
	 * 公钥
	 */
	public static final String NOTE_PUBLIC_KEY="publicKey";
	/**
	 * 私钥
	 */
	public static final String NOTE_PRIVATE_KEY="privateKey";

	@Id
	@GenericGenerator(name = "idGenerator", strategy = "uuid")
	@GeneratedValue(generator = "idGenerator")
	private String uuid;

	/**
	 * 生成时间
	 */
   	@Column(name = "created_time" )
	private String createdTime;

	/**
	 * 查询条件
	 * 生成时间起
	 */
	@Transient
	@JsonIgnore
	private String createdTimeBegin;

	/**
	 * 查询条件
	 * 生成时间止
	 */
	@Transient
	@JsonIgnore
	private String createdTimeEnd;

	/**
	 * 更新时间
	 */
   	@Column(name = "updated_time" )
	private String updatedTime;

	/**
	 * 删除时间
	 */
   	@Column(name = "delete_time" )
	private String deleteTime;

	/**
	 * 是否已删除,1-是，2-否
	 */
   	@Column(name = "deleted" )
	private Boolean deleted;

	/**
	 * 密钥名称
	 */
   	@Column(name = "name" )
    @Size(min = 4,max = 50)
	@NotBlank
	private String name;

	/**
	 * 密钥类型--来自SecretKeyType枚举
	 */
   	@Column(name = "secret_type" )
	private String secretType;

	/**
	 * 有效期
	 */
   	@Column(name = "expiration" )
	private String expiration;

	/**
	 * 密钥状态，有效，已过期，定时任务进行处理
	 */
	@Column(name = "status" )
	private String status;

	/**
	 * 密钥算法
	 */
   	@Column(name = "algorithm" )
	private String algorithm;

	/**
	 * 备注，对称密钥为空，非对称的标注是公钥还是私钥
	 */
	@Column(name = "note" )
	private String note;

	/**
	 * 密钥算法长度
	 */
   	@Column(name = "bit_length" )
	private String bitLength;

	/**
	 * 加密模式	cbc、ecb
	 */
   	@Column(name = "mode" )
	private String mode;

	/**
	 * 用户id
	 */
   	@Column(name = "creator_id" )
	private String creatorId;

	/**
	 * 密钥密码
	 */
	@Column(name = "password")
	@JsonIgnore
	private String password;


	/**
	 * 密钥格式，PKCS1/PKCS8等
	 */
	@Column(name = "key_format" )
	private String keyFormat;

	/**
	 * 输出格式，hex,pem等
	 */
	@Column(name = "output_format" )
	private String outputFormat;


	/**
	 * 二级主密钥id
	 */
	@Column(name = "kek_id" )
	private String kekId;

	/**
	 * 下载url,格式为/v1/secrets/{secret_uuid}/payload
	 */
	@Transient
	private String downloadRef;

}
